package cn.tedu.weibo.controller;

import cn.tedu.weibo.pojo.dto.CommentDTO;
import cn.tedu.weibo.pojo.entity.Comment;
import cn.tedu.weibo.pojo.vo.CommentVO;
import cn.tedu.weibo.response.JsonResult;
import cn.tedu.weibo.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/comments/")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("add-new")
    public JsonResult addNew(CommentDTO comment){
        commentService.addNew(comment);
        return JsonResult.ok();
    }

    @GetMapping("{id}")
    public JsonResult listByWeiboId(@PathVariable Long id){
        List<CommentVO> list  =commentService.listByWeiboId(id);
        // System.out.println(list);
        return JsonResult.ok(list);
    }
}
